import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

const routes: Array<RouteRecordRaw> = [
  { path: "/", redirect: "/login" },
  { path: "/login", component: () => import("@/views/login/LoginView.vue") },
  { path: "/rest", component: () => import("@/views/rest/RestView.vue") },
  // { path: "/home", component: () => import("@/views/home/HomeView.vue") },
  {
    path: "/home",
    component: () => import("@/views/home/addView.vue"),
    beforeEnter: (to, from, next) => {
      if (localStorage.getItem("token")) {
        next();
      } else {
        next("/login");
      }
    },
    children: [
      // 订单路由
      {
        path: "/home/data",
        component: () => import("@/views/home/Data/DataView.vue"),
        children: [
          {
            path: "/home/data/num",
            component: () => import("@/views/home/Data/num/numView.vue"),
          },
          {
            path: "/home/data/yh",
            component: () => import("@/views/home/Data/yongh/YhView.vue"),
          },
        ],
      },
      // 促销管理
      {
        path: "/home/cxgl",
        component: () => import("@/views/home/CXGL/CxView.vue"),
        children: [
          {
            path: "/home/cxgl/miaos",
            component: () => import("@/views/home/CXGL/miaos/MiaoView.vue"),
          },
          {
            path: "/home/cxgl/ms",
            component: () => import("@/views/home/CXGL/miaos/Mstziew.vue"),
          },
          {
            path: "/home/cxgl/yhq",
            component: () => import("@/views/home/CXGL/yhq/YouView.vue"),
          },
          // 优惠券跳转
          {
            path: "/home/cxgl/yhqtz",
            component: () => import("@/views/home/CXGL/yhq/YHQTZ.vue"),
          },
        ],
      },
      // 订单管理
      {
        path: "/home/ddgl",
        component: () => import("@/views/home/DDGL/DdView.vue"),
        children: [
          {
            path: "/home/ddgl/quanb",
            component: () => import("@/views/home/DDGL/quanb/QuanView.vue"),
          },
        ],
      },
      // 商品管理
      {
        path: "/home/spgl",
        component: () => import("@/views/home/SPGL/SpView.vue"),
        children: [
          {
            path: "/home/spgl/sp",
            component: () => import("@/views/home/SPGL/Sp/SpView.vue"),
          },
          {
            path: "/home/spgl/Commodity",
            component: () => import("@/views/home/SPGL/Sp/CommodityView.vue"),
          },
        ],
      },
    ],
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

export default router;
